package com.spundhan.xtrac;

import java.util.ArrayList;

import android.app.Dialog;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

import com.aretha.slidemenu.SlideMenu;
import com.spundhan.xtrac.adapters.TripsAdapter;

public class TripsActivity extends SlidiningMenuActivity {

	private SlideMenu mSlideMenu;
	
	ListView list;
	
	TripsAdapter adapter;
	
	@Override
	public void onContentChanged() {
		super.onContentChanged();
		setSlideRole(R.layout.activity_trips);
		setSlideRole(R.layout.activity_side_menu);
	
		getActionBar().setHomeButtonEnabled(true);
		list = (ListView) findViewById(R.id.list_trips);
		ArrayList<String> data = new ArrayList<String>();
		data.add("test");
		data.add("test");
		data.add("test");
		data.add("test");
		
		ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_checked,data);
		
		adapter = new TripsAdapter(getApplicationContext(), R.layout.trip_list_row, R.id.trip_name,data);
		list.setAdapter(adapter);
		list.setActivated(true);
		list.setItemChecked(3, true);
		
		mSlideMenu = getSlideMenu();

		mSlideMenu.setSlideMode(SlideMenu.MODE_SLIDE_WINDOW);
		
		getActionBar().setTitle("");

	}
	
	
/*	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_trips);

		getActionBar().setHomeButtonEnabled(true);
		list = (ListView) findViewById(R.id.list_trips);
		ArrayList<String> data = new ArrayList<String>();
		data.add("test");
		data.add("test");
		data.add("test");
		data.add("test");
		
		ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_checked,data);
		
		adapter = new TripsAdapter(getApplicationContext(), R.layout.trip_list_row, R.id.trip_name,data);
		list.setAdapter(adapter);
		list.setActivated(true);
		list.setItemChecked(3, true);
		
		mSlideMenu = getSlideMenu();

		mSlideMenu.setSlideMode(SlideMenu.MODE_SLIDE_WINDOW);
		
		getActionBar().setTitle("");
		
	}*/
	
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
//		Intent in = new Intent(getApplicationContext(),MainActivity.class);
//		in.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
//		startActivity(in);
//		overridePendingTransition(R.anim.left_to_right, R.anim.abc_fade_out);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.trips, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.

		switch (item.getItemId()) {
		case android.R.id.home:
			Toast.makeText(getApplicationContext(), "click", Toast.LENGTH_LONG)
					.show();
			mSlideMenu.open(false, true);
			break;

		case R.id.menu_trip_add:
			showDialog();
			getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

		default:
			break;
		}

		return true;
	}

	public void showDialog() {

		final Dialog dialog = new Dialog(this);
		dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dialog.setContentView(R.layout.dialog_trip_add);

		final EditText editName = (EditText) dialog
				.findViewById(R.id.edit_trip);
		Button btnAdd = (Button) dialog.findViewById(R.id.btn_ok);
		Button btnCancel = (Button) dialog.findViewById(R.id.btn_cancel);

		btnAdd.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				editName.getText().toString();

			}
		});

		btnCancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				dialog.dismiss();
			}
		});

		dialog.show();

	}
}
